from rest_framework import serializers
from .models import CourseCategory


class CourseCategoryModelSerializer(serializers.ModelSerializer):
    """课程分类的序列化器"""

    class Meta:
        model = CourseCategory
        fields = ['id', 'name']


from .models import Course, Teacher


class TeacherModelSerializer(serializers.ModelSerializer):
    """
    老师的序列化器
    """

    class Meta:
        model = Teacher
        fields = ['id', 'name', 'title', 'signature', 'brief', 'image']


class CourseModelSerializer(serializers.ModelSerializer):
    """"
    课程信息的序列化器
    """
    # 序列化器嵌套
    teacher = TeacherModelSerializer()  # 嵌套单个

    # teacher_list = TeacherModelSerializer(many=True) # 嵌套多个
    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "students", "lessons", "pub_lessons",
                  "price", "teacher", 'free_lesson_list', "discount_name", "discount_price"]


class CourseRetrieveModelSerializer(serializers.ModelSerializer):
    """课程详情页序列化器"""
    teacher = TeacherModelSerializer()

    class Meta:
        model = Course
        fields = ["name", "course_img", "course_video", "brief", "level_name", "pub_date", "period",
                  "attachment_path", "students", "lessons", "pub_lessons", "price", "teacher", "discount_name",
                  "discount_price", 'has_time']


from .models import CourseChapter


class CourseChapterModelSerializer(serializers.ModelSerializer):
    """课程章节的序列化器"""

    class Meta:
        model = CourseChapter
        fields = ['id', 'name', 'chapter', 'summary', 'lesson_data']
